package com.robot.log.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import com.robot.log.pojo.SearchLog;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * searchLog数据访问接口
 *
 * @author wuyunbin
 */
public interface SearchLogDao extends JpaRepository<SearchLog, String>, JpaSpecificationExecutor<SearchLog> {
    /**
     * 根据memberId和keywords查找搜索记录,同一用户搜索相同关键词只记录一次
     *
     * @param memberId
     * @param keywords
     * @return
     */
    public SearchLog findByMemberIdAndKeywords(String memberId, String keywords);

    /**
     * 查找最热门的10条数据
     *
     * @return
     */
    @Query(value = "select keywords from search_log group by keywords order by count(keywords) desc limit 10;", nativeQuery = true)
    public List<String> findTop10SearchLogsDesc();
}
